package edu.luc.cs.udp.client;

import java.net.*;

/**
 * Simple client to test NetKernel UDP transport. Runs outside of NetKernel.
 * @author epwest
 *
 */
public class UDPClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		//Client socket
		SocketAddress a = new InetSocketAddress("127.0.0.1", 8091);
		DatagramSocket clientSocket = new DatagramSocket(a);
		
		
		//Request
		String requestURI = "hello/netkernel/java";
		byte[] requestData = requestURI.getBytes("UTF-8");

		//Server socket
		InetAddress IPAddress = InetAddress.getByName("127.0.0.1");
		DatagramPacket requestPacket = new DatagramPacket(requestData, requestData.length, IPAddress, 8090);
		   
		clientSocket.send(requestPacket);
		
		byte[] receiveData = new byte[1024];
		DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);		
		clientSocket.receive(receivePacket);
		String representation = new String(receivePacket.getData());

		System.out.println("Representation: " + representation);
		clientSocket.close();
	}

}
